#include <fstream>
#include <iostream>

using namespace std;

int main ( int argc, char *argv[] )
{
  if ( argc != 2 )
	cout<<"usage: "<< argv[0] <<" <filename>\n";
  else {
    ifstream the_file ( argv[1] );
    if ( !the_file.is_open() )
		cout<<"Could not open file\n";
    else {
		const int arraySizeIncrease = 1000000;
		int arraySize = arraySizeIncrease, wordCount = 0;
		char** wordListArray = new char* [arraySize];
		char wordSize [512];
		ifstream fileInputStream(inputFile);
		while (fileInputStream >> wordSize )
		{
			wordListArray[wordCount] = new char [strlen (wordSize) + 1];
			strcpy (wordListArray[wordCount], wordSize);
			wordCount++;
			//If the File has more then 1000000 Words!
			if (wordCount % arraySizeIncrease == 0)
			{
				char** oldSize = wordListArray;
				arraySize += arraySizeIncrease;
				wordListArray = new char* [arraySize];
				memcpy (wordListArray, oldSize, wordCount * sizeof(char*));
				delete oldSize;
			}
		}
    }
	fileInputStream.close();
  }
}
